home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 4 / Precision Software Applications Silver Collection Volume 4 (1993).iso / stats / chadyn.exe / YPLOT.C < prev    next >
Text File  |  1988-12-12  |  52KB  |  1,923 lines

  1.  
  2. /******************* (C) 1986,7,8 by JAMES A. YORKE **************************/
  3. /******************************** YPLOT.C ***********************************/
  4. /* This file YPLOT.C contains routines that are tools
  5.     for plotting on the screen and in the core
  6.             James Yorke               */
  7.  
  8. /*     Routines in YPLOT.c
  9. These are routines that are essentially independent of the map being studied.
  10.  
  11. add_to_pic  in YDISK.C
  12. block_plot(x1,x2,y1,y2)
  13. boot_crt        
  14. clearp
  15. connectp(x,y)     connects x,y to x_c,y_c 
  16.     double x,y;
  17. connect2(x1,y1,x2,y2)
  18. cross(x1,y1,m,n,picnum,crossnum) reverses m dots on each side of screen point 
  19.         (row,col) and n above and below; picnum = 1 means the 
  20.         screen; = 2 means the core picture  
  21.     double x1,y1;    int m,n,picnum;
  22. definitely_erase_line()
  23. draw_box    
  24. erase_line()
  25. fetchPic
  26. fileFailureWarning()
  27. FindPixel(x1,y1,picnum) this routine puts the coordinates in the
  28.         vector COL,ROW; if picnum == 1, they are for the crt while 
  29.         if == 2 they are for the core copy 
  30.     double x1,y1;int picnum;
  31. maskdef  
  32. picOff(COLnum1,ROWnum1,COLnum2,ROWnum2)
  33.     int COLnum1,ROWnum1,COLnum2,ROWnum2;
  34. td0 monochrome
  35. td  to disk
  36. plot(x,y)       
  37. PlotComplaint
  38. PrintBoxCoordinates() if printer > 1; prints at top of screen
  39. pprint(onprint) in YPLOT2.C  
  40. resetDiameters
  41. reverseCore(x,y)
  42. ScreenConstants()    sets ax,bx where x = 0,00,1,2
  43. scrOff(COLnum1,ROWnum1,COLnum2,ROWnum2)
  44.     int COLnum1,ROWnum1,COLnum2,ROWnum2;
  45. int set_box             sets X_low thru Y_upp 
  46. double ticGap(dif) dif is double; called by ticMarks
  47. ticMarks() called by draw_box when ticFlag == ON 
  48.  
  49. */
  50.  
  51.  
  52. #include "yinclud.h"
  53.  
  54. /*#define DEBUG*/
  55.  
  56. #ifndef X11
  57.  
  58. #define BLANK 0
  59.  
  60. #ifdef DESMET
  61. #define _setcolor(x) null(x)
  62. #endif /* DESMET */
  63.  
  64. /* char far pic1[CORESIZE];   65280 = Memory size in core */
  65. char    far *pic1 = NULL;
  66. char    far *pic2 = NULL;
  67. char    far *pic4 = NULL;
  68. char    far *pic8 = NULL;
  69. char    one = 1,
  70.         two = 2,
  71.         four = 4,
  72.         eight = 8;        /* bytes for pic arrays */
  73. unsigned char   byte255 = 255;
  74. /*unsigned char byteCount = 0;
  75. */
  76. int     byteCount = 0;
  77. char    lastByte;
  78. FILE    *fp, *gp;        /* for disk i/o */
  79.  
  80.  
  81. /* The core(i.e. pic1[]) and screen operations are independent   */
  82. /* #define ABS(x) ( (x)>0 ? x : -x) */
  83.  
  84. static int      sROW,
  85.                 sCOL;
  86.  
  87. int     xmax,
  88.         ymax;            /* set by FindPixel */
  89.  
  90. static double   xCorPix[5],
  91.                 yCorPix[5];
  92. static double   xDifRecip,
  93.                 yDifRecip;    /* set by screenConstants */
  94. static int      LeftScrEdge[5],
  95.                 RtScrEdge[5],
  96.                 TopScrEdge[5],
  97.                 BotScrEdge[5];
  98.  
  99. /* note: ROW and COL are int in yextern.h */
  100.  
  101. #ifndef unix
  102. #include <malloc.h>        /* required only for function declarations */
  103. #include <stdlib.h>        /* for ANSI compatibility -- malloc only */
  104. #endif /* unix */
  105.  
  106. static  halfscrcols,
  107.         halfscrrows;
  108. extern char     printstatus;    /* set in YPRINTER.C, = status byte of printer;
  109.                    see also _bios_printer() which is a MSC
  110.                    function */
  111. char    far *pic0 = NULL;
  112. #endif    /* X11 */
  113.  
  114. /****************************SUBROUTINES********************************/
  115.  
  116.  
  117.  
  118. stoplines()        /* turn off the drawing of connected lines */
  119. {
  120. #ifdef X11
  121.     startpt = NULL;
  122. #else
  123.     x_c = -9999.0;
  124. #endif /* X11 */
  125.     return;
  126. }
  127.  
  128. fetchPic(addFlag)
  129. int     addFlag;
  130.  /* This routine is for fetching a picture from *DiskFileName and loading it in
  131.     pic[]; previous contents of pic1[] are obliterated; the assumption is made
  132.     that the number of horizontal lines(= corerows in number) used in making
  133.     the the picture saved in the file is the same as currently being used; this
  134.     should be changed */
  135. {
  136. #ifdef X11
  137.     printf("Disk i/o of pictures is not yet implemented\n");
  138. #else
  139.     unsigned        coord;
  140.     double  corewdth,
  141.             scrnwdth;
  142.     double  col_ratio;
  143.     double  row_ratio;
  144.     int     cflag = NO,
  145.             numColorPlanes;
  146.     int     eight_rows;
  147.     int     i,
  148.             k,
  149.             m;
  150.     int     fgetc();    /* this is a function; getc() is not */
  151.     char    getNextChar();
  152.     char    colorByte = color;
  153.     char    picChar;
  154.     char    docstr[82];
  155.     char   *cp,
  156.            *fgets();    /* recall fgets does return the carriage return
  157.                    */
  158.  
  159. #ifdef DEBUG
  160.     fprintf(stderr, "fetchPic(%d): level=%d file=%s\n", addFlag, level,
  161.         DiskFileName);
  162.     pause(1.5);
  163. #endif /* DEBUG */
  164.     if(colorPlanes == 0 && level == 2) {
  165.         PRINT
  166. "You do not have the memory to store this picture. Use while plotting\n");
  167.         PRINT
  168. "by hitting : and then using command FD or AFD      \n");
  169.         return;
  170.     }
  171.     picNameFlag = YES;    /* records the fact that this file has been
  172.                    accessed; */
  173. #ifdef DESMET
  174.     gp = fopen(DiskFileName, OPENFORREADING);/* open to  "r" read  */
  175. #endif /* DESMET */
  176. #ifdef MS
  177.     gp = fopen(DiskFileName, "rb");/* open to  "rb" read binary */
  178. #endif /* MS */
  179.     if(gp == NULL) {
  180.         PRINT
  181. "The program cannot open %s. Perhaps the name is wrong            \n"
  182.             ,DiskFileName);
  183.         return;
  184.     }
  185.  
  186.     do {
  187.         cp = fgets(docstr, 82, gp);
  188.         if(cp == 0) {
  189.             PRINT "read error  \n");
  190.             return;
  191.         }
  192.     } while(docstr[0] != '#');
  193.                 /* fgets gets a new line and returns 0 on end
  194.                    of file or on error; the last line of text
  195.                    starts with '#' */
  196.     if(docstr[1] == '4')
  197.         sscanf(docstr + 2, "%d %d %d\n", &corecols, &corerows,
  198.                 &numColorPlanes);
  199.     else {
  200.         if(docstr[1] == 'c')
  201.             cflag = YES;/* = c means compressed */
  202.         sscanf(docstr + 2, "%d %d \n", &corecols, &corerows);
  203.     }
  204.     corewdth = corecols;
  205.     scrnwdth = scrncols;
  206.     col_ratio = scrnwdth / corewdth;
  207.     row_ratio = scrnrows / (8.* corerows);/* note decimal point */
  208. #ifndef MAINFRAME
  209.     if(level >= PROCESS && addFlag == NO) {
  210.         scr_clr();    /* in desmets pcio.a */
  211.         if(printer == 3)
  212.             bottomPrint();
  213.     }
  214. #endif /* MAINFRAME */
  215.  
  216.     if(docstr[1] != '4') {
  217.         byteCount = 0;
  218.         for(k = 0; k < corerows; k++)
  219.             for(m = 0; m < corecols; m++) {
  220.                 coord = m * corerows + k;
  221.  
  222.  
  223.             /*     coord = m*corerows+k; */
  224.             /*     pic1[coord]= fgetc(gp); */
  225.                 if(cflag == NO)/* not compressed */
  226.                     picChar = fgetc(gp);
  227.                 else {
  228.                     picChar = getNextChar(gp);
  229.                 /* for compressed files */
  230.                 }
  231.                 if(addFlag == NO) {
  232.                     if(colorPlanes >= 4) {
  233.                     /* need colorByte parens below because
  234.                        != is carried out before & */
  235.                         pic8[coord] = ((colorByte & eight) ? picChar : 0);
  236.                         pic4[coord] = ((colorByte & four) ? picChar : 0);
  237.                         pic2[coord] = ((colorByte & two) ? picChar : 0);
  238.                         pic1[coord] = ((colorByte & one) ? picChar : 0);
  239.                     }
  240.                     else
  241.                         if(colorPlanes >= 1) {
  242.                             pic1[coord] = ((colorByte & one) ? picChar : 0);
  243.                         }
  244.                 }
  245.                 if(addFlag == YES) {
  246.                 /* means the picture gets added in to whatever
  247.                    is present */
  248.                     if(colorPlanes >= 4) {
  249.                         if((colorByte & eight) != 0)
  250.                 /* need colorByte parens because != is carried
  251.                    out before & */
  252.                             pic8[coord] = pic8[coord] | picChar;
  253.                         if((colorByte & four) != 0)
  254.                             pic4[coord] = pic4[coord] | picChar;
  255.                         if((colorByte & two) != 0)
  256.                             pic2[coord] = pic2[coord] | picChar;
  257.                         if((colorByte & one) != 0)
  258.                             pic1[coord] = pic1[coord] | picChar;
  259.                     }
  260.                     else
  261.                         if(colorPlanes >= 1) {
  262.                             pic1[coord] = pic1[coord] | picChar;
  263.                         }
  264.                 }
  265.  
  266.             /* now add byte to screen; same as in add_to_pic() */
  267.                 if(level >= PROCESS) {
  268.                 /* coord = ColTimesCorerows+row; */
  269.                     eight_rows = 8 * k;/* k = row */
  270.                     for(rowbit = 0; rowbit < 8; rowbit++)
  271.                         if((picChar & mask[rowbit]) != 0) {
  272.                 /* this examines the specific bit in pic1[] to
  273.                    see if it is 0 */
  274.                             COL = col_ratio * m;
  275.                 /* m = col */
  276.                             ROW = (eight_rows + rowbit) * row_ratio;
  277.                             setPixel(COL, ROW, color);
  278.                 /* this is part of the Desmet graphics package;
  279.                    it writes a dot on the screen */
  280.                         /* in MSC, the 3rd variable in
  281.                            setPixel is a dumby and
  282.                            changes in the color must be
  283.                            set independently */
  284.                         }
  285.                 }/* end if level */
  286.             }
  287.     }
  288.     if(docstr[1] == '4' && colorPlanes < 4) {
  289.         if(addFlag == NO)
  290.             clearp();
  291.         for(i = 0; i < 4; i++) {
  292.             byteCount = 0;
  293.             for(k = 0; k < corerows; k++)
  294.                 for(m = 0; m < corecols; m++) {
  295.                     coord = m * corerows + k;
  296.                     pic1[coord] |= getNextChar(gp);
  297.                 /* for compressed files */
  298.                 }
  299.         }
  300.         if(level > 2) {
  301.             boot = 1;
  302.             boot_crt();
  303.         }
  304.     }
  305.     if(docstr[1] == '4' && addFlag == NO && colorPlanes >= 4) {
  306.         byteCount = 0;
  307.         for(k = 0; k < corerows; k++)
  308.             for(m = 0; m < corecols; m++) {
  309.                 coord = m * corerows + k;
  310.                 pic1[coord] = getNextChar(gp);
  311.                 /* for compressed files */
  312.             }
  313.         byteCount = 0;
  314.         for(k = 0; k < corerows; k++)
  315.             for(m = 0; m < corecols; m++) {
  316.                 coord = m * corerows + k;
  317.                 pic2[coord] = getNextChar(gp);
  318.                 /* for compressed files */
  319.             }
  320.         byteCount = 0;
  321.         for(k = 0; k < corerows; k++)
  322.             for(m = 0; m < corecols; m++) {
  323.                 coord = m * corerows + k;
  324.                 pic4[coord] = getNextChar(gp);
  325.                 /* for compressed files */
  326.             }
  327.         byteCount = 0;
  328.         for(k = 0; k < corerows; k++)
  329.             for(m = 0; m < corecols; m++) {
  330.                 coord = m * corerows + k;
  331.                 pic8[coord] = getNextChar(gp);
  332.                 /* for compressed files */
  333.             }
  334.         if(level > 2) {
  335.             boot = 1;
  336.             boot_crt();
  337.         }
  338.     }
  339.     if(docstr[1] == '4' && addFlag == YES) {
  340.         byteCount = 0;
  341.         for(k = 0; k < corerows; k++)
  342.             for(m = 0; m < corecols; m++) {
  343.                 coord = m * corerows + k;
  344.                 pic1[coord] = getNextChar(gp) | pic1[coord];
  345.             }
  346.         byteCount = 0;
  347.         for(k = 0; k < corerows; k++)
  348.             for(m = 0; m < corecols; m++) {
  349.                 coord = m * corerows + k;
  350.                 pic2[coord] = getNextChar(gp) | pic2[coord];
  351.             }
  352.         byteCount = 0;
  353.         for(k = 0; k < corerows; k++)
  354.             for(m = 0; m < corecols; m++) {
  355.                 coord = m * corerows + k;
  356.                 pic4[coord] = getNextChar(gp) | pic4[coord];
  357.             }
  358.         byteCount = 0;
  359.         for(k = 0; k < corerows; k++)
  360.             for(m = 0; m < corecols; m++) {
  361.                 coord = m * corerows + k;
  362.                 pic8[coord] = getNextChar(gp) | pic8[coord];
  363.             }
  364.         if(level > 2) {
  365.             boot = 1;
  366.             boot_crt();
  367.         }
  368.     }
  369.     fclose(gp);
  370. #endif    /* X11 */
  371. }
  372.  
  373. #ifndef X11
  374. int     picAlloc() 
  375. {    /* returns the number of planes; pic has already been allocated */
  376.     int     i;
  377.  
  378.     if((pic1 = (char far *) _fmalloc(CORESIZE * sizeof(char))) == NULL)
  379.         return(0);
  380.     if((pic2 = (char far *) _fmalloc(sizeof(char) * CORESIZE)) == NULL)
  381.         return(1);
  382.     if((pic4 = (char far *) _fmalloc(sizeof(char) * CORESIZE)) == NULL)
  383.         return(2);
  384.     if((pic8 = (char far *) _fmalloc(sizeof(char) * CORESIZE)) == NULL)
  385.         return(3);
  386.     i = 4;
  387. /*
  388.     while((pic0 = (char far *)  _fmalloc(sizeof(char)*1000)) != NULL)
  389.         i++;
  390. */
  391.     return(i);
  392. }
  393.  
  394.  
  395. plot(x1, y1)            /* This plots a point on the screen AND sets a
  396.                    bit to 1 in the matrix pic1[], provided
  397.                    x1,y1 is within the window to be plotted. If
  398.                    it is not within the window and if
  399.                    "diameter" is > 0, the routine checks to see
  400.                    if it is within "diameters[ScrnSec]" times
  401.                    the width and within "diameters[ScrnSec]
  402.                    times the height of the screen. If it is not
  403.                    close enough to the screen based on this
  404.                    criterion, the program is reset to SINGLE
  405.                    STEP mode to prevent overflow; the screen
  406.                    coordinates used: ROW,COL are preserved
  407.                    since they are external */
  408. double  x1,
  409.         y1;
  410. {
  411.     char maskByte;
  412.     unsigned        ROWcoord;
  413.     double  d,
  414.             dd,
  415.             xdif,
  416.             ydif,
  417.             xx,
  418.             yy;
  419.  
  420.  /* sCOL and sROW are for drawing lines */
  421.     sCOL = COL = xScrPix[ScrnSec] * ((xx = x1 - X_lower));
  422.     sROW = ROW = yScrPix[ScrnSec] * ((yy = Y_upper - y1));
  423.  
  424.     if((X_upper - x1) * xx < 0 || yy * (Y_lower - y1) > 0) {
  425.                 /* if outside screen */
  426.         stoplines();     /* for stopping drawing connected lines */
  427.         xdif = X_upper - X_lower;/* this could be defined once */
  428.         ydif = Y_upper - Y_lower;
  429.         d = diameters[ScrnSec];
  430.         dd = d * (1 + d);
  431.         if(d >= 0) {
  432.             if((X_upper - x1) * xx > dd * xdif * xdif
  433.                     || yy * (Y_lower - y1) > dd * ydif * ydif) {
  434.                 PlotComplaint();
  435.             }
  436.         }
  437.         return;
  438.     }
  439.     if(windowflag[0] == ON && ScrnSec == 0) {
  440.         if(windowflag[1] == ON)
  441.             if(COL <= halfscrcols && ROW <= halfscrrows) {
  442.                 setCoreCOLROW(x1, y1);
  443.                 /* sets COL and ROW for Core for connectp */
  444.                 return;/* if inside window ss */
  445.             }
  446.         if(windowflag[2] == ON)
  447.             if(COL >= halfscrcols && ROW <= halfscrrows) {
  448.                 setCoreCOLROW(x1, y1);
  449.                 /* sets COL and ROW for Core for connectp */
  450.                 return;/* if inside window ss */
  451.             }
  452.         if(windowflag[3] == ON)
  453.             if(COL <= halfscrcols && ROW >= halfscrrows) {
  454.                 setCoreCOLROW(x1, y1);
  455.                 /* sets COL and ROW for Core for connectp */
  456.                 return;/* if inside window ss */
  457.             }
  458.         if(windowflag[4] == ON)
  459.             if(COL >= halfscrcols && ROW >= halfscrrows) {
  460.                 setCoreCOLROW(x1, y1);
  461.                 /* sets COL and ROW for Core for connectp */
  462.                 return;/* if inside window ss */
  463.             }
  464.  
  465.     }
  466.     else
  467.     if(ScrnSec != 0) {
  468.             FindPixel(x1, y1, SCRN);
  469.             sCOL = COL;/* sCOL and sROW are for drawing lines */
  470.             sROW = ROW;
  471.     }
  472.         /* this routine puts the coordinates in the vector COL,ROW;*/
  473.  
  474.     if(IsCross0Set == YES) {
  475.                 /* if the cross is not turned off, and the new
  476.                    dot to be plotted is in the cross, it will
  477.                    cause erased when the cross goes */
  478.         turnoff(BIGCROSS);
  479.     }
  480.     setPixel(COL, ROW, color);
  481.                 /* this is part of the Desmet graphics package;
  482.                    it writes a dot on the screen; it is about
  483.                    10% faster than inline execution of Bob
  484.                    Buchal's write_dot() */
  485.  /* in MSC, the 3rd variable in setPixel is a dumby and changes in the color
  486.     must be set independently */
  487.  
  488. #ifndef MAINFRAME
  489.     if(cross0flag == 1)    /* set using interrupt 'k' */
  490.         SetCross(BIGCROSS);
  491. #endif /* ifndef MAINFRAME */
  492.  
  493.  /* now plot point on the internal memory copy of the picture */
  494.  
  495.     if(ScrnSec == 0) {
  496.         COL = (*xCorPix) * xx;
  497.         ROW = (*yCorPix) * yy;
  498.     }
  499.     else
  500.         FindPixel(x1, y1, CORE);
  501.  
  502.     maskByte = mask[(ROW % 8)];
  503.     ROWcoord = COL * corerows + ROW / 8;
  504.     corePixel(ROWcoord, maskByte);
  505.                 /* this colors a core pixel as specified by
  506.                    coord the color "color" */
  507. }
  508.  
  509. setCoreCOLROW(x1, y1)        /* sets COL and ROW for Core for connectp */
  510. double  x1,
  511.         y1;
  512. {
  513.     if(ScrnSec == 0) {
  514.         COL = (*xCorPix) * (x1 - X_lower);
  515.         ROW = (*yCorPix) * (Y_upper - y1);
  516.     }
  517.     else
  518.         FindPixel(x1, y1, CORE);/* sets COL and ROW */
  519. }
  520.  
  521. PlotComplaint() {        /* called by plot() */
  522.     scr_rowcol(1, 0);
  523.  
  524.     PRINT
  525. "X = %15.12lf   Y = %15.12lf            \n", y[X_coord], y[Y_coord]);
  526.     PRINT
  527. "This point is too far from screen: more than %lf diameters from the screen\n",
  528.         diameters[ScrnSec]);
  529.  
  530. #ifndef MAINFRAME
  531.     PRINT
  532. "Program now enters SINGLE STEP mode to prevent overflow\n");
  533.     PRINT
  534. "Reinitialize using 'i' or 'm' or cursor keys and/or reset menu's parameters\n"
  535. );
  536. #endif /* ifndef MAINFRAME */
  537.  
  538.     PRINT
  539. "\nTo change 'diameters', use command SD \n"
  540.         );
  541.  
  542. #ifndef MAINFRAME    
  543. cycle = 2;        /* single step mode; setting cycle = 2 tells
  544.                    Interrupt() not to call plot() since that
  545.                    would give an infinite loop */
  546.     Interrupt();
  547. #else
  548. /* This is what we do in MAINFRAME mode in case of overflow */ 
  549.         taskFlag = -1;    /* this means that when plotsomething() is
  550.                    called, we do not plot a dot */
  551.         level = 2;
  552.         PRINT "DROPPING BACK TO MENU DUE TO LEAVING BOX");
  553. #endif /* ifndef MAINFRAME */
  554. }
  555.  
  556.  
  557.  
  558. clrWindow() {
  559.     stoplines();         /* for stopping drawing connected lines */
  560.     SignIsOn = 0;        /* sign about jump size */
  561.     IsCross0Set = NO;    /* screen cross at y0 is not set */
  562.     IsCross1Set = NO;    /* screen cross at y1 is not set */
  563.     if(ScrnSec == 0) {
  564.         scr_clr();    /* in desmets pcio.a */
  565.         clearp();
  566.     }
  567.     if(ScrnSec == 1) {
  568.         picOff(0, 0, corecols / 2, corerows / 2);
  569.         scrOff(0, 0, scrncols / 2, scrnrows / 2);
  570.     }
  571.     if(ScrnSec == 2) {
  572.         picOff(corecols / 2, 0, corecols, corerows / 2);
  573.         scrOff(scrncols / 2, 0, scrncols, scrnrows / 2);
  574.     }
  575.     if(ScrnSec == 3) {
  576.         picOff(0, corerows / 2, corecols / 2, corerows);
  577.         scrOff(0, scrnrows / 2, scrncols / 2, scrnrows);
  578.     }
  579.     if(ScrnSec == 4) {
  580.         picOff(corecols / 2, corerows / 2, corecols, corerows);
  581.         scrOff(scrncols / 2, scrnrows / 2, scrncols, scrnrows);
  582.     }
  583. }
  584.  
  585.  
  586. ticMarks(flag)            /* called by draw_box when ticFlag == ON; flag
  587.                    = 2 means that an extra fine set of tic
  588.                    marks should be drawn with 1/5 the spacing;
  589.                    the extra set is small and should show up
  590.                    better when the picture is printed */
  591. int     flag;
  592. {
  593.     int     size = 100,
  594.             sign;
  595.     double  gap,
  596.             ticGap(), x, v;
  597.     double  moduloAB();
  598.  
  599.     scr_rowcol(2, 0);
  600.     if(flag == 2)
  601.         size = 170;
  602.  
  603.     gap = ticGap(X_upp - X_low);
  604.     if(gap == 0) {
  605.         PRINT "CANNOT DRAW TIC MARKS; BOX HAS 0 WIDTH      \n");
  606.         return;
  607.     }
  608.     if(flag == 2)
  609.         gap = gap *.2;
  610.     x = X_low - moduloAB(X_low, 0., gap) + gap;
  611.                 /* moduloAB() is  a number between 0. and gap,
  612.                    -- even if gap is negative  */
  613.     x = x + gap *.000001;
  614.     erase_line();
  615.     PRINT "Horizontal spacing between tic marks: %lf starting at %lf\n"
  616.         ,gap, x);
  617.     if(X_upp < X_low)
  618.         sign = -1;
  619.     else
  620.         sign = 1;
  621.     for(; sign * (X_upp - x) > 0; x += gap) {/* top and bottom */
  622. /*
  623.         = HORIZSCRN 3 means horizontal line segment on screen
  624.         = VERTSCRN  4 means vertical line segment on screen
  625.         = HORIZCORE 5 means horizontal line segment on core
  626.         = VERTCORE  6 means vertical line segment on core
  627. */
  628.         plotY =.99999 * Y_upp +.00001 * Y_low;
  629.         drawcross(x, plotY, corecols / size, 8 * corerows / size, VERTCORE);
  630.     /* permanent cross in core */
  631.         drawcross(x, plotY, scrncols / size, scrnrows / size, VERTSCRN);
  632.     /* permanent cross in crt */
  633.         plotY =.99999 * Y_low +.00001 * Y_upp;
  634.         drawcross(x, plotY, corecols / size, (8 * corerows) / size, VERTCORE);
  635.         drawcross(x, plotY, scrncols / size, scrnrows / size, VERTSCRN);
  636.     }
  637.  
  638.  
  639.     gap = ticGap(Y_upp - Y_low);/* has same sign as argument of ticGap */
  640.     if(gap == 0) {
  641.         PRINT "CANNOT DRAW TIC MARKS; BOX HAS 0 HEIGHT            \n");
  642.         return;
  643.     }
  644.     if(flag == 2)
  645.         gap = gap *.2;
  646.     v = Y_low - moduloAB(Y_low, 0., gap) + gap;
  647.     v = v + gap *.000001;
  648.     PRINT "Vertical spacing between tic marks: %lf starting at %lf\n"
  649.         ,gap, v);
  650.  
  651.     if(Y_upp < Y_low)
  652.         sign = -1;
  653.     else
  654.         sign = 1;
  655.     for(; sign * (Y_upp - v) > 0; v += gap) {/* sides */
  656.         plotX =.99999 * X_upp +.00001 * X_low;
  657.         drawcross(plotX, v, corecols / size, (8 * corerows) / size, HORIZCORE);
  658.         drawcross(plotX, v, scrncols / size, scrnrows / size, HORIZSCRN);
  659.  
  660.         plotX =.99999 * X_low +.00001 * X_upp;
  661.         drawcross(plotX, v, corecols / size, (8 * corerows) / size, HORIZCORE);
  662.         drawcross(plotX, v, scrncols / size, scrnrows / size, HORIZSCRN);
  663.     }
  664. }
  665.  
  666. double  ticGap(dif)        /*  returns distance between tic marks; input
  667.                    difference between left and right scales;
  668.                    returns a number starting with a digit
  669.                    5,6,7,8, or 9; Hence .0056... returns .005,
  670.                    and -.0056 becomes -.005; if first digit is
  671.                    1, number is multiplied by 5; if first digit
  672.                    is less than 5, number is multiplied by 2; 
  673.                 */
  674. double  dif;
  675. {
  676.     double  old = dif;    /* keeps track of change in size of dif */
  677.  
  678.     if(dif == 0)
  679.         return(0.);
  680.     if(dif < 0)
  681.         dif = -dif;
  682.     while(dif < 1)
  683.         dif = 10 * dif;
  684.     while(dif > 10)
  685.         dif = dif / 10;
  686.     if(dif < 2)
  687.         dif = dif * 5.;
  688.     if(dif < 5)
  689.         dif = dif * 2.;
  690.     dif = 1./ (dif / old);
  691.     return(dif);
  692. }
  693. connect2 (x1, y1, x2, y2)
  694. double  x1,
  695.         y1,
  696.         x2,
  697.         y2;
  698. {
  699.     int     flag0,
  700.             flagm;
  701.  
  702.     flag0 = cross0flag;    /* when cross0flag = YES, the large cross will
  703.                    be plotted at each dot, and erased before
  704.                    the next cross is drawn */
  705.     cross0flag = NO;
  706.     flagm = modFlag;
  707.     modFlag = NO;        /* used for drawing boxes in case a mod has
  708.                    been hit */
  709.  
  710.     plot(x1, y1);
  711.     connectp(x1, y1);    /* this is needed for setting constants; see
  712.                    also draw_box() */
  713.     connectp(x2, y2);
  714.  
  715.     stoplines();         /* for stopping drawing connected lines */
  716.     cross0flag = flag0;
  717.     modFlag = flagm;
  718. }
  719.  
  720. connectp(x, y)            /* connects x,y to x_c,y_c; you must have
  721.                    called plot(x_c,y_c) because this routine
  722.                    sets sCOL and sROW which are for drawing
  723.                    lines; see connect2() for an example of how
  724.                    to call it. This routine is temporarily
  725.                    turned off by setting x_c t0 -9999. */
  726.  /* **** note the following definitions from ScreenConstants(): xDifRecip =
  727.     1/fabs(X_upper-X_lower); yDifRecip = 1/fabs(Y_upper-Y_lower);  sCOL and
  728.     sROW are set by plot, so a point must be plotted before using connect ****** 
  729.  */
  730. double  x,
  731.         y;
  732. {
  733.     char    maskByte;
  734.     unsigned        coord;
  735.     int     xpix,
  736.             ypix;
  737.     int     oldsCOL,
  738.             oldsROW,
  739.             oldcCOL,
  740.             oldcROW,
  741.             temp;
  742.     int     n,
  743.             abs();
  744.     int     maximum,
  745.             xp,
  746.             yp;
  747.     long    CoreColDif,
  748.             CoreRowDif;
  749.     long    coldif,
  750.             rowdif;
  751.     double  fabs(), xfraction, yfraction, Old_x_c;
  752.  
  753.     xfraction = fabs(x - x_c) * xDifRecip;
  754.     xp = corecols * xfraction;
  755.     yfraction = fabs(y - y_c) * yDifRecip;
  756.     yp = core_row_bits * yfraction;
  757.     if((maximum = xp) < yp)
  758.         maximum = yp;
  759.  
  760.     oldsCOL = sCOL;
  761.     oldsROW = sROW;
  762.     oldcCOL = COL;
  763.     oldcROW = ROW;
  764.  /* in cases where there is a big change in x or y because of evaluating
  765.     something modulo something, we jump */
  766.     Old_x_c = x_c;
  767.     x_c = x;
  768.     y_c = y;
  769.  
  770.     plot(x, y);        /* this sets x_c = -9999 if x,y is outside its
  771.                    frame; it also can set x_c = -9999. */
  772.     if(x_c == -9999.|| Old_x_c == -9999.
  773.             || modFlag == YES
  774.             || maximum < 2) {
  775.         return;
  776.     }
  777.  
  778.     else {
  779.     /* first SCREEN line */
  780.         coldif = sCOL - oldsCOL;
  781.         rowdif = sROW - oldsROW;
  782.         if(coldif >= abs(rowdif))/* in particular coldif > 0 */
  783.             for(n = 1; n < coldif; n++) {
  784.                 temp = (rowdif * n) / coldif;
  785.                 setPixel(oldsCOL + n, oldsROW + temp, color);
  786.             /* in MSC, the 3rd variable in setPixel is a dumby and
  787.                changes in the color must be set independently */
  788.             }    /* in MSC, the 3rd variable is a dumby and
  789.                    changes in the color must be set
  790.                    independently */
  791.         else if(-coldif >= abs(rowdif))
  792.             /* in particular coldif > 0 */
  793.             for(n = -1; n > coldif; n--) {
  794.                 temp = (rowdif * n) / coldif;
  795.                 setPixel(oldsCOL + n, oldsROW + temp, color);
  796.             }
  797.         else if(rowdif >= abs(coldif))
  798.             /* in particular rowdif > 0 */
  799.             for(n = 1; n < rowdif; n++) {
  800.                 temp = (coldif * n) / rowdif;
  801.                 setPixel(oldsCOL + temp, oldsROW + n, color);
  802.             }
  803.         else if(-rowdif >= abs(coldif))
  804.             /* in particular coldif > 0 */
  805.             for(n = -1; n > rowdif; n--) {
  806.                 temp = (coldif * n) / rowdif;
  807.                 setPixel(oldsCOL + temp, oldsROW + n, color);
  808.             }
  809.  
  810.     /* now CORE line */
  811.         CoreColDif = COL - oldcCOL;
  812.         CoreRowDif = ROW - oldcROW;
  813.  
  814.         if(CoreColDif >= abs(CoreRowDif))
  815.                 /* in particular CoreColDif > 0 */
  816.             for(n = 1; n < CoreColDif; n++) {
  817.                 temp = (CoreRowDif * n) / CoreColDif;
  818.                 xpix = oldcCOL + n;
  819.                 ypix = oldcROW + temp;
  820.                 coord = xpix * corerows + ypix / 8;
  821.                 maskByte = mask[ypix % 8];
  822.                 corePixel(coord, maskByte);
  823.                 /* this colors a core(=pic) pixel as specified
  824.                    by coord the color "color" */
  825.             }
  826.         else if(-CoreColDif >= abs(CoreRowDif))
  827.             for(n = -1; n > CoreColDif; n--) {
  828.                 temp = (CoreRowDif * n) / CoreColDif;
  829.                 xpix = oldcCOL + n;
  830.                 ypix = oldcROW + temp;
  831.                 coord = xpix * corerows + ypix / 8;
  832.                 maskByte = mask[ypix % 8];
  833.                 corePixel(coord, maskByte);
  834.             /* this colors a core(=pic) pixel as specified
  835.                by coord the color "color" */
  836.             }
  837.         else if(CoreRowDif >= abs(CoreColDif))
  838.             for(n = 1; n < CoreRowDif; n++) {
  839.                 temp = (CoreColDif * n) / CoreRowDif;
  840.                 xpix = oldcCOL + temp;
  841.                 ypix = oldcROW + n;
  842.                 coord = xpix * corerows + ypix / 8;
  843.                 maskByte = mask[ypix % 8];
  844.                 corePixel(coord, maskByte);
  845.                 /* this colors a core(=pic) pixel as specified
  846.                    by coord the color "color" */
  847.             }
  848.         else if(-CoreRowDif >= abs(CoreColDif))
  849.             for(n = -1; n > CoreRowDif; n--) {
  850.                 temp = (CoreColDif * n) / CoreRowDif;
  851.                 xpix = oldcCOL + temp;
  852.                 ypix = oldcROW + n;
  853.                 coord = xpix * corerows + ypix / 8;
  854.                 maskByte = mask[ypix % 8];
  855.                 corePixel(coord, maskByte);
  856.                 /* this colors a core(=pic) pixel as specified
  857.                    by coord the color "color" */
  858.             }
  859.     }
  860. }
  861.  
  862.  
  863.  
  864. #ifndef unix
  865. #include <conio.h>
  866. #endif /* unix */
  867.  
  868. scrOff(COLnum1, ROWnum1, COLnum2, ROWnum2)
  869. int     COLnum1,
  870.         ROWnum1,
  871.         COLnum2,
  872.         ROWnum2;
  873. {
  874. #ifndef MAINFRAME
  875.     _setcolor(BLANK);
  876.     _rectangle(_GFILLINTERIOR, COLnum1, ROWnum1, COLnum2, ROWnum2);
  877.     _setcolor(color);
  878. #endif /* ifndef MAINFRAME */
  879. }
  880.  
  881.  
  882. picOff(COLnum1, ROWnum1, COLnum2, ROWnum2)/* CORE COPY; see also scrOff();
  883.         each row is a row of bytes */
  884. int     COLnum1,
  885.         ROWnum1,
  886.         COLnum2,
  887.         ROWnum2;
  888. {
  889.     unsigned        coord;
  890.     int     ROWdif = ROWnum2 - ROWnum1;
  891.  
  892.     for(COL = COLnum1; COL < COLnum2; COL++) {
  893.         coord = COL * corerows + ROWnum1;
  894. #ifdef DESMET
  895.         _setmem(pic1 + coord, ROWdif, 0);
  896. #endif /* DESMET */
  897. #ifdef MS
  898.         clearline(coord, ROWdif);
  899.                 /* this is written as a function to optimize
  900.                    register allocation */
  901. #endif /* MS */
  902.     }
  903. }
  904.  
  905. #ifdef MS
  906. clearline(coord, ROWdif)    /* this is separated out to make use of
  907.                    automatic register variables in loops; this
  908.                    is the routine that must be sped up */
  909. int     ROWdif;
  910. unsigned        coord;
  911. {
  912.     unsigned        cd;
  913.     int     end;
  914.     char    far * pp1;
  915.     char    far * pp2;
  916.     char    far * pp4;
  917.     char    far * pp8;
  918.  
  919.     end = coord + ROWdif;
  920.     if(colorPlanes == 0)
  921.         return;
  922.     if(colorPlanes >= 4) {
  923.         pp1 = pic1 + coord;
  924.         pp2 = pic2 + coord;
  925.         pp4 = pic4 + coord;
  926.         pp8 = pic8 + coord;
  927.         for(cd = coord; cd < end; cd++) {
  928.             *(pp1++) = 0;
  929.             *(pp2++) = 0;
  930.             *(pp4++) = 0;
  931.             *(pp8++) = 0;
  932.         }
  933.     }
  934.     else
  935.         if(colorPlanes >= 1) {
  936.             for(pp1 = pic1 + coord, cd = coord; cd < end; cd++)
  937.                 *(pp1++) = 0;
  938.         }
  939. }
  940. #endif /* MS */
  941.  
  942.  
  943. block_plot(x1, x2, y1, y2)    /* This plots a point on the screen AND sets a
  944.                    bit to 1 in the matrix pic1[].  */
  945. float   x1,
  946.         x2,
  947.         y1,
  948.         y2;
  949. {
  950.     unsigned        coord;
  951.     long    ROW2,
  952.             COLnum1,
  953.             COLnum2,
  954.             ROWnum1,
  955.             ROWnum2;
  956.  
  957.     FindPixel((double)x1, (double)y1, SCRN);/*sets COL and ROW */
  958.  /* this routine puts the coordinates in the vector COL,ROW; */
  959.     COLnum1 = COL;
  960.     ROWnum1 = ROW;
  961.     FindPixel((double)x2, (double)y2, SCRN);
  962.     COLnum2 = COL;
  963.     ROWnum2 = ROW;
  964.  
  965.     if((X_upper -x1)*(X_lower -x1) <= 0 && (Y_upper -y1)*(Y_lower -y1) <=0)
  966.     {
  967.         for(COL = COLnum1; COL < COLnum2; COL++)/* COL is an int */
  968.             for(ROW = ROWnum1; ROW < ROWnum2; ROW++) {
  969. #ifndef MAINFRAME
  970.                 setPixel(COL, ROW, color);
  971.                 /* this is part of the Desmet graphics package;
  972.                    it writes a dot on the screen */
  973.             /* in MSC, the 3rd variable in setPixel is a dumby and
  974.                changes in the color must be set independently */
  975. #endif /* MAINFRAME */
  976.             }
  977.     }
  978.     else
  979.         return;
  980.  /* now plot points on the internal memory copy of the picture */
  981.     FindPixel((double)x1, (double)y1, CORE);
  982.     COLnum1 = COL;
  983.     ROWnum1 = ROW;
  984.     FindPixel((double)x2, (double)y2, CORE);
  985.     COLnum2 = COL;
  986.     ROWnum2 = ROW;
  987.  
  988.     for(COL = COLnum1; COL < COLnum2; COL++)
  989.         for(ROW2 = ROWnum1; ROW2 < ROWnum2; ROW2++)
  990.             if(COL >= 0 && COL < corecols
  991.                     && ROW2 >= 0 && ROW2 < core_row_bits) {
  992.                 coord = COL * corerows + (ROW2 / 8);
  993.                 corePixel(coord, mask[(ROW2 % 8)]);
  994.             /* this colors a core(=pic) pixel as specified by
  995.                coord the color "color" */
  996.             }
  997. }
  998.  
  999. boot_crt() {            /* This is for use with input -99, 99, -699,
  1000.                    699, etc, in parameter menu ... ; it does
  1001.                    depends on whether "boot" is 0 or 1;first it
  1002.                    calculates the constants needed to plot
  1003.                    points, constants that are needed by
  1004.                    "plot()";if "boot" is 0, the screen and
  1005.                    pic1[] are cleared; when "boot" = 1; the
  1006.                    picture in pic1[] is put on the screen; in
  1007.                    particular when a picture has been made and
  1008.                    the program returns to the menu, there is
  1009.                    still a copy of the picture in pic1[] and
  1010.                    this routine reboots it to the screen;   if
  1011.                    "boxx" == 1, it draws a box; */
  1012.  
  1013.     unsigned        coord;
  1014.     char    pc1,
  1015.             pc2,
  1016.             pc4,
  1017.             pc8,
  1018.             maskByte,
  1019.             pc;
  1020.     int     ColTimesCorerows;
  1021.     int     col,
  1022.             row,
  1023.             eight_rows,
  1024.             i;
  1025.     double  col_ratio,
  1026.             row_ratio;
  1027.     double  corewdth,
  1028.             scrnwdth;
  1029.     int     int1 = 1,
  1030.             int2 = 2,
  1031.             int4 = 4,
  1032.             int8 = 8;
  1033.     int     prevColor = color,
  1034.             activeColor = color;
  1035.  
  1036.     ScreenConstants();    /* defines ax,bx where x = 0,00,1,2 */
  1037.  
  1038.     corewdth = corecols;
  1039.     scrnwdth = scrncols;
  1040.     IsCross0Set = NO;    /* screen cross at y0 is not set */
  1041.     IsCross1Set = NO;    /* screen cross at y1 is not set */
  1042. #ifndef MAINFRAME
  1043.     scr_clr();        /* in desmets pcio.a */
  1044.     if(printer == 3)
  1045.         bottomPrint();
  1046. #endif /* MAINFRAME */
  1047.  
  1048.     if(boot == 0)
  1049.         clearp();
  1050.     if(boot == 0 && ScrnSec == 0) {
  1051.                 /* this turns window overlap prevention off */
  1052.         for(i = 0; i <= 4; i++)
  1053.             windowflag[i] = OFF;
  1054.     }
  1055.     pc1 = pc2 = pc4 = pc8 = 0;
  1056.     col_ratio = scrnwdth / corewdth;
  1057.     row_ratio = scrnrows / (8.* corerows);/* note decimal point */
  1058.     if(boot != 0 && colorPlanes > 1) 
  1059.     {    for(col = 0; col < corecols; col++) 
  1060.         {   COL = col_ratio * col;
  1061.             for(eight_rows = 0, row = 0, coord = col * corerows
  1062.                     ; row < corerows
  1063.                     ; coord++, row++, eight_rows += 8) 
  1064.             {
  1065.             pc1 = pic1[coord];
  1066.             pc2 = pic2[coord];
  1067.             if(colorPlanes >= 3)
  1068.                 pc4 = pic4[coord];
  1069.             if(colorPlanes >= 4)
  1070.                 pc8 = pic8[coord];
  1071.  
  1072.             if((pc = pc1 | pc2 | pc4 | pc8) != 0) 
  1073.             {   for(rowbit = 0; rowbit < 8; rowbit++) 
  1074.                 {    maskByte = mask[rowbit];
  1075.                 if(pc & maskByte) /* i.e. if non zero */
  1076.                 {    color = ((pc1 & maskByte) ? int1 : 0)
  1077.                     + ((pc2 & maskByte) ? int2 : 0)
  1078.                     + ((pc4 & maskByte) ? int4 : 0)
  1079.                     + ((pc8 & maskByte) ? int8 : 0);
  1080.                     if(color != prevColor) 
  1081.                     {    _setcolor(color);
  1082.                     prevColor = color;
  1083.                     }
  1084.                     ROW = (eight_rows + rowbit) * row_ratio;
  1085.                     setPixel(COL, ROW, color);
  1086.                         /* in MSC, the 3rd variable in
  1087.                            setPixel is a dumby and
  1088.                            changes in the color must be
  1089.                            set independently */
  1090.                     }
  1091.                 }/* end for  */
  1092.                 }/* end if pc */
  1093.             }/* end for(eight_rows = 0... */
  1094.         }        /* end: for col, for row, and if */
  1095.     }/* end if boot */
  1096.     if(boot != 0 && colorPlanes == 1) 
  1097.     {   for(col = 0; col < corecols; col++) 
  1098.         {    COL = col_ratio * col;
  1099.         ColTimesCorerows = col * corerows;
  1100.         for(eight_rows = 0, row = 0, coord = ColTimesCorerows
  1101.                 ; row < corerows
  1102.                 ; coord++, row++, eight_rows += 8) {
  1103.             if((pc = pic1[coord]) != 0) {
  1104.                 for(rowbit = 0; rowbit < 8; rowbit++) {
  1105.                     maskByte = mask[rowbit];
  1106.                     if(pc & maskByte)/*i.e. if non zero */ 
  1107.                     {  ROW = 
  1108.                          (eight_rows + rowbit) * row_ratio;
  1109.                        setPixel(COL,ROW, color);
  1110.                         /* in MSC, the 3rd variable in
  1111.                            setPixel is a dumby and
  1112.                            changes in the color must be
  1113.                            set independently */
  1114.                     }
  1115.                 }/* end if */
  1116.             }
  1117.         }
  1118.         }        /* end: for col, for row, and if */
  1119.     }
  1120.     boot = 0;
  1121.     if(boxx == 1)
  1122.         draw_box();
  1123.     color = activeColor;
  1124.     _setcolor(color);
  1125. }
  1126.  
  1127.  
  1128. bottomPrint()
  1129. {
  1130.     scr_rowcol(11,0);  /* move cursor to bottom left; */
  1131.     PRINT 
  1132. "INTERRUPT MENU (* for help)\n");
  1133.     PRINT 
  1134. "spacebar   return to Menu \n");
  1135.     PRINT 
  1136. "*A Actions menu \n");
  1137.     PRINT 
  1138. "*S Screen menu \n");
  1139.     PRINT 
  1140. "*H Help level menu \n");
  1141.  
  1142. }
  1143.  
  1144. corePixel(coord, maskByte)    /* this colors a core(=pic) pixel as specified
  1145.                    by coord the color "color" */
  1146. unsigned        coord;
  1147. char    maskByte;
  1148. {
  1149.     char    colorByte = color%16;/* color mod 16 */
  1150.  
  1151.     if(colorPlanes == 0)
  1152.         return;
  1153.     if(colorPlanes >= 4) {
  1154.         pic1[coord] = ((colorByte & one)
  1155.                 ? pic1[coord] | maskByte
  1156.                 : pic1[coord] & ~maskByte);
  1157.         pic2[coord] = ((colorByte & two)
  1158.                 ? pic2[coord] | maskByte
  1159.                 : pic2[coord] & ~maskByte);
  1160.         pic4[coord] = ((colorByte & four)
  1161.                 ? pic4[coord] | maskByte
  1162.                 : pic4[coord] & ~maskByte);
  1163.         pic8[coord] = ((colorByte & eight)
  1164.                 ? pic8[coord] | maskByte
  1165.                 : pic8[coord] & ~maskByte);
  1166.     }
  1167.     else
  1168.         if(colorPlanes >= 1) {
  1169.             pic1[coord] = ((colorByte & one)
  1170.                     ? pic1[coord] | maskByte
  1171.                     : pic1[coord] & ~maskByte);
  1172. /*        pic1[coord]= pic1[coord] | maskByte;*/
  1173.         }
  1174. }
  1175.  
  1176. char    getNextChar(gp)
  1177. FILE *gp;
  1178. {
  1179.     int     fgetc();    /* this is a function; getc() is not */
  1180.  
  1181.     if(byteCount != 0) {
  1182.         byteCount--;
  1183.         return(lastByte);
  1184.     }
  1185.     if(byteCount == 0) {
  1186.         C = fgetc(gp);
  1187.         if(C == 0 || C == byte255) {
  1188.             lastByte = C;
  1189.             byteCount = fgetc(gp) - 1;
  1190.             if(byteCount < 0)
  1191.                 byteCount += 256;
  1192.             return(C);
  1193.         }
  1194.         else
  1195.             return(C);
  1196.     }
  1197.     return(C);        /* we will not get here */
  1198. }
  1199.  
  1200. FindPixel(xx, yy, picnum)    /* this routine puts the coordinates in the
  1201.         vector COL,ROW; if picnum == SCRN == 1, 
  1202.         they are for the crt while if= CORE = 2, they are for the core
  1203.                    copy */
  1204. double  xx,
  1205.         yy;
  1206. int     picnum;
  1207. {
  1208.     int     x,
  1209.             y;
  1210.  
  1211.     xx -= X_lower;
  1212.     yy -= Y_upper;        /* notce the sign is incorrect here but this
  1213.                    will be made up for with the omission of a
  1214.                    sign later */
  1215.  
  1216.     if(picnum == SCRN) {    /* crt */
  1217.         xmax = scrncols;
  1218.         ymax = scrnrows;
  1219.         x = xScrPix[ScrnSec] * xx;
  1220.         y = -yScrPix[ScrnSec] * yy;
  1221.     }
  1222.     else if(picnum == CORE) {        /* core */
  1223.         xmax = corecols;
  1224.         ymax = core_row_bits;
  1225.         x = xCorPix[ScrnSec] * xx;
  1226.         y = -yCorPix[ScrnSec] * yy;
  1227.     }
  1228.     switch(ScrnSec)  {
  1229.     case 1:     /* upper left */
  1230.         x = x / 2;
  1231.         y = y / 2;
  1232.         break;
  1233.     case 2:        /* upper right */
  1234.         x = (x + xmax) / 2;
  1235.         y = y / 2;
  1236.         break;
  1237.     case 3:        /* lower left */
  1238.         x = x / 2;
  1239.         y = (y + ymax) / 2;
  1240.         break;
  1241.     case 4:        /* lower right */
  1242.         x = (x + xmax) / 2;
  1243.         y = (y + ymax) / 2;
  1244.         break;
  1245.     case 0:
  1246.         break;
  1247.     }
  1248.     COL = x;
  1249.     ROW = y;
  1250.     return;
  1251. }
  1252.  
  1253.  
  1254. clearp() {            /* Sets matrix pic1[] = zero */
  1255. #ifdef DESMET
  1256.     _setmem(pic1, CORESIZE, 0);
  1257. #endif /* DESMET */
  1258. #ifdef MS
  1259.     unsigned        cd,
  1260.                     coresize = CORESIZE;
  1261.     if(colorPlanes >= 4)
  1262.         for(cd = 0; cd < coresize; cd++) {
  1263.             pic1[cd] = pic2[cd] = pic4[cd] = pic8[cd] = 0;
  1264.         }
  1265.     else
  1266.         if(colorPlanes >= 1)
  1267.             for(cd = 0; cd < coresize; cd++) {
  1268.                 pic1[cd] = 0;
  1269.             }
  1270. #endif /* MS */
  1271.     if(TDFreq != 0) {
  1272.         TDFreq = 0;
  1273.         erase_line();
  1274.         PRINT
  1275. "****** TDFreq set = 0; picture will not automatically be stored. ********\n");
  1276.     }
  1277.     if(TDTime != 0) {
  1278.         TDTime = 0;
  1279.         erase_line();
  1280.         PRINT
  1281. "****** TDTIME set = 0; picture will not automatically be stored. ********\n");
  1282.     }
  1283.     if(TDTime == 0 && runTime == 0)
  1284.         timeFlag = NO;
  1285. }
  1286.  
  1287. draw_box() {            /* draws a box with x coordinates X_low,X_upp
  1288.                    and y coordinates Y_low,Y_upp; enough pixels
  1289.                    are used to guarantee a solid line for both
  1290.                    the screen and pic1[] ( at least
  1291.                    vertically); routine now aims at getting
  1292.                    enough pixels plotted horizontally for
  1293.                    pic1[]; cross0flag is temporarily set to 0
  1294.                    so that no cross is drawn during the drawing
  1295.                    of the box */
  1296.     int     flag;
  1297.     double  X_small,
  1298.             Y_small;
  1299.  
  1300.     if(set_box() != 0) {
  1301.         if(ticFlag > OFF)
  1302.             ticMarks(1);
  1303.                 /*  set_box() sets X_low thru Y_upp; set_box ==
  1304.                    0 if box is partially outside window */
  1305.         if(ticFlag == 2)
  1306.             ticMarks(2);
  1307.                 /* draws an extra set of fine tic marks */
  1308.     }
  1309.     PrintBoxCoordinates();    /* if printer > 1; prints at top of screen */
  1310.  /* dots plotted at top and bottom of screen and pic1[] */
  1311.     Y_small =.00001 * (Y_upp - Y_low);
  1312.     X_small =.00001 * (X_upp - X_low);
  1313.     flag = cross0flag;    /* when cross0flag = 1, the large cross will be
  1314.                    plotted at each dot, and erased before the
  1315.                    next cross is drawn */
  1316.     cross0flag = 0;
  1317.  
  1318.  
  1319.     modFlag = NO;        /* used for drawing boxes in case a mod has
  1320.                    been hit */
  1321.     plot(X_low + X_small, Y_low + Y_small);
  1322.     connectp(X_low + X_small, Y_low + Y_small);
  1323.     connectp(X_upp - X_small, Y_low + Y_small);
  1324.     connectp(X_upp - X_small, Y_upp - Y_small);
  1325.     connectp(X_low + X_small, Y_upp - Y_small);
  1326.     connectp(X_low + X_small, Y_low + Y_small);
  1327.     stoplines();         /* for stopping drawing connected lines */
  1328.     cross0flag = flag;
  1329. }
  1330.  
  1331.  
  1332.  
  1333. PrintBoxCoordinates() {    /* if printer > 1; prints at top of screen */
  1334.     scr_rowcol(20, 0);
  1335.     if(printer > 1) {
  1336.         set_box();    /* sets X_low thru Y_upp */
  1337.         erase_line();
  1338.         PRINT
  1339. "box coords: LEFT: %lf  RIGHT: %lf   BOTTOM: %lf  TOP: %lf       \n"
  1340.             ,X_low, X_upp, Y_low, Y_upp);
  1341.     }
  1342. }
  1343.  
  1344.  
  1345.  
  1346. erase_line() {            /*  Under condition of SCREEN(see ydefines),
  1347.                    this prints a line of blanks on the screen
  1348.                    to ensure that when a new PARTIAL line is
  1349.                    printed, there will be no left over digits
  1350.                    and letters from a previous printing; notice
  1351.                    the cursor returns to the beginning of the
  1352.                    line -- that is there is no line feed */
  1353. #ifndef MAINFRAME
  1354.     if(SCREEN) {
  1355.         PRINT
  1356. "                                                                             "
  1357.             );
  1358.         PRINT "  \r");
  1359.     }
  1360. #endif /* MAINFRAME */
  1361. }
  1362.  
  1363. definitely_erase_line() {    /* This is for the case where we want a blank
  1364.                    line even though printer == 0; for use in
  1365.                    YINTRPT.C this prints a line of blanks on
  1366.                    the screen to ensure that when a new PARTIAL
  1367.                    line is printed, there will be no left over
  1368.                    digits and letters from a previous printing;
  1369.                    notice the cursor returns to the beginning
  1370.                    of the line -- that is there is no line feed
  1371.                    */
  1372. #ifndef MAINFRAME
  1373.     PRINT
  1374. "                                                                             "
  1375.         );
  1376.     PRINT "  \r");
  1377. #endif /* ifndef MAINFRAME */
  1378. }
  1379.  
  1380.  
  1381. maskdef(MASK)
  1382. char    MASK[];
  1383. {
  1384.     MASK[7] = 1;
  1385.     MASK[6] = 2;
  1386.     MASK[5] = 4;
  1387.     MASK[4] = 8;
  1388.     MASK[3] = 16;
  1389.     MASK[2] = 32;
  1390.     MASK[1] = 64;
  1391.     MASK[0] = 128;
  1392. }
  1393.  
  1394. td() {
  1395.     char    C;
  1396.     unsigned        coord;
  1397.     int     p0,
  1398.             i,
  1399.             handleC();
  1400.  
  1401.     if(colorPlanes == 0) {
  1402.         PRINT
  1403. "You do not have the memory to keep a high resolution copy;\n");
  1404.         PRINT
  1405. "Since it does not exist, it cannot be stored    \n");
  1406.         return;
  1407.     }
  1408.  
  1409. #ifdef DESMET
  1410.     fp = fopen(DiskFileName, "w");/* open to  "w" write */
  1411. #endif /* DESMET */
  1412. #ifdef MS
  1413.     fp = fopen(DiskFileName, "wb");/* append binary */
  1414. #endif /* MS */
  1415.     if(fp == 0L) {
  1416.         PRINT "CANNOT OPEN FILE %s; abort picture save\n"
  1417.             ,DiskFileName);
  1418.         return;
  1419.     }
  1420.     if(level == 2)
  1421.         scr_clr();
  1422.     DumpData(fp);
  1423.  
  1424. /*    fprintf(fp,"# 960 68 1\n");   */
  1425.     fprintf(fp, "#4 %d %d %d\n", corecols, corerows, colorPlanes);
  1426.  
  1427.     if(colorPlanes >= 1) {
  1428.         byteCount = 0;
  1429.         for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
  1430.             for(i = 0; i < corecols; i++) {
  1431.                 coord = i * corerows + p0;
  1432.                 C = pic1[coord];
  1433.                 if(handleC(C, fp) == NO)
  1434.                 {
  1435.                     fclose(fp);
  1436.                     return;
  1437.                 }
  1438.             }
  1439.  
  1440.     /* now finish off case where there is a string of 0's or 255's */
  1441.         if(byteCount != 0)
  1442.                 if(tryPutc(byteCount, fp) == NO)
  1443.                 {
  1444.                     fclose(fp);
  1445.                     return;
  1446.                 }
  1447.     }
  1448.     if(colorPlanes >= 2) {
  1449.         byteCount = 0;
  1450.         for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
  1451.             for(i = 0; i < corecols; i++) {
  1452.                 coord = i * corerows + p0;
  1453.                 C = pic2[coord];
  1454.                 if(handleC(C, fp) == NO)
  1455.                 {
  1456.                     fclose(fp);
  1457.                     return;
  1458.                 }
  1459.             }
  1460.  
  1461.     /* now finish off case where there is a string of 0's or 255's */
  1462.         if(byteCount != 0)
  1463.             if(tryPutc(byteCount, fp) == NO)
  1464.             {
  1465.                 fclose(fp);
  1466.                 return;
  1467.             }
  1468.     }
  1469.     if(colorPlanes >= 3) {
  1470.         byteCount = 0;
  1471.         for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
  1472.             for(i = 0; i < corecols; i++) {
  1473.                 coord = i * corerows + p0;
  1474.                 C = pic4[coord];
  1475.                 if(handleC(C, fp) == NO)
  1476.                 {
  1477.                     fclose(fp);
  1478.                     return;
  1479.                 }
  1480.             }
  1481.  
  1482.     /* now finish off case where there is a string of 0's or 255's */
  1483.         if(byteCount != 0)
  1484.             if(tryPutc(byteCount, fp) == NO)
  1485.             {
  1486.                 fclose(fp);
  1487.                 return;
  1488.             }
  1489.     }
  1490.     if(colorPlanes >= 4) {
  1491.         byteCount = 0;
  1492.         for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
  1493.             for(i = 0; i < corecols; i++) {
  1494.                 coord = i * corerows + p0;
  1495.                 C = pic8[coord];
  1496.                 if(handleC(C, fp) == NO)
  1497.                 {
  1498.                     fclose(fp);
  1499.                     return;
  1500.                 }
  1501.             }
  1502.  
  1503.     /* now finish off case where there is a string of 0's or 255's */
  1504.         if(byteCount != 0)
  1505.             if(tryPutc(byteCount, fp) == NO)
  1506.             {
  1507.                 fclose(fp);
  1508.                 return;
  1509.             }
  1510.     }
  1511.     for(i = 0; i < 100; i++)/* pad end of file a bit with 0's */
  1512.         if(tryPutc(C = 0, fp) == NO)/* returns no if file is full */
  1513.         {
  1514.             fclose(fp);
  1515.             return;
  1516.         }
  1517.     for(i = 0; i < 100; i++) {/* pad end of file a bit with 0's */
  1518.         if(tryPutc(C = 0, fp) == NO)/* returns no if file is full */
  1519.         {
  1520.             fclose(fp);
  1521.             return;
  1522.         }
  1523.         if(tryPutc(byte255, fp) == NO)
  1524.                 /* returns no if file is full */
  1525.         {
  1526.             fclose(fp);
  1527.             return;
  1528.         }
  1529.     }
  1530.     fclose(fp);
  1531.     if(level < PROCESS)
  1532.         scr_clr();
  1533.  
  1534.     if(level >= PROCESS) {
  1535.         scr_rowcol(0, 0);
  1536.         erase_line();
  1537.         ret_erase_line(5);
  1538.         scr_rowcol(3, 0);
  1539.         PRINT
  1540. "============================================================================="
  1541.             );
  1542.         scr_rowcol(2, 0);
  1543.     }
  1544.     if(level < PROCESS)
  1545.         MainMenu();
  1546.     erase_line();
  1547.     PRINT
  1548. "    PICTURE HAS BEEN STORED IN DISKFILE:      %s            \n\n",
  1549.         DiskFileName);
  1550. }
  1551.  
  1552.  
  1553.  
  1554. td0 () {            /* does compress-- monochrome output */
  1555.     char    C;
  1556.     char    pc1,
  1557.             pc2,
  1558.             pc4,
  1559.             pc8,
  1560.             maskByte,
  1561.             pc;
  1562.     unsigned        coord;
  1563.     int     p0,
  1564.             i,
  1565.             handleC();
  1566.     FILE * fopen();
  1567.  
  1568.     if(colorPlanes == 0) {
  1569.         PRINT
  1570. "You do not have the memory to keep a high resolution copy;\n");
  1571.         PRINT
  1572. "Since it does not exist, it cannot be stored    \n");
  1573.         return;
  1574.     }
  1575.  
  1576. #ifdef DESMET
  1577.     fp = fopen(DiskFileName, "w");/* open to  "w" write */
  1578. #endif /* DESMET */
  1579. #ifdef MS
  1580.     fp = fopen(DiskFileName, "wb");/* append binary */
  1581. #endif /* MS */
  1582.     if(fp == 0L) {
  1583.         PRINT "CANNOT OPEN FILE %s; abort picture save\n"
  1584.             ,DiskFileName);
  1585.         return;
  1586.     }
  1587.     if(level == 2)
  1588.         scr_clr();
  1589.     DumpData(fp);
  1590.  
  1591. /*    fprintf(fp,"# 960 68 1\n");   */
  1592.     fprintf(fp, "#c %d %d \n", corecols, corerows);
  1593.  
  1594.     for(p0 = 0; p0 < corerows; p0++)/* p0 = line number */
  1595.         for(i = 0; i < corecols; i++) {
  1596.                 /* sends line to disk if disk ==1 */
  1597.             coord = i * corerows + p0;
  1598.             if(colorPlanes >= 1)
  1599.                 pc1 = pic1[coord];
  1600.             else
  1601.                 pc1 = 0;
  1602.             if(colorPlanes >= 2)
  1603.                 pc2 = pic2[coord];
  1604.             else
  1605.                 pc2 = 0;
  1606.             if(colorPlanes >= 3)
  1607.                 pc4 = pic4[coord];
  1608.             else
  1609.                 pc4 = 0;
  1610.             if(colorPlanes >= 4)
  1611.                 pc8 = pic8[coord];
  1612.             else
  1613.                 pc8 = 0;
  1614.  
  1615.             C = pc1 | pc2 | pc4 | pc8;
  1616.  
  1617. /*        C = pic1[coord];old monochrome version */
  1618.  
  1619.             if(handleC(C, fp) == NO)
  1620.             {
  1621.                 fclose(fp);
  1622.                 return;
  1623.             }
  1624.         }
  1625.  /* now finish off case where there is a string of 0's or 255's */
  1626.     if(byteCount != 0)
  1627.         if(tryPutc(byteCount, fp) == NO)
  1628.         {
  1629.             fclose(fp);
  1630.             return;
  1631.         }
  1632.  
  1633.     fclose(fp);
  1634.     if(level < PROCESS)
  1635.         scr_clr();
  1636.  
  1637.     if(level >= PROCESS) {
  1638.         scr_rowcol(0, 0);
  1639.         erase_line();
  1640.         ret_erase_line(5);
  1641.         scr_rowcol(3, 0);
  1642.         PRINT
  1643. "============================================================================="
  1644.             );
  1645.         scr_rowcol(2, 0);
  1646.     }
  1647.     if(level < PROCESS)
  1648.         MainMenu();
  1649.     erase_line();
  1650.     PRINT
  1651. "    PICTURE HAS BEEN STORED IN DISKFILE:      %s            \n\n",
  1652.         DiskFileName);
  1653. }
  1654.  
  1655. /*    char byte255 = 255,byteCount = 0,lastByte;*/
  1656.  
  1657.  
  1658. int     handleC(C, fp)
  1659. char    C;
  1660. FILE * fp;
  1661. {
  1662.     int     tryPutc();
  1663.  
  1664.     if(C != 0 && C != byte255) {
  1665.         if(byteCount == 0) {
  1666.             if(tryPutc(C, fp) == NO)
  1667.                 /* returns no if file is full */
  1668.                 return(NO);
  1669.             return(YES);
  1670.         }
  1671.         else {        /* byteCount != 0 */
  1672.             if(tryPutc(byteCount, fp) == NO)
  1673.                 return(NO);
  1674.             byteCount = 0;
  1675.             if(tryPutc(C, fp) == NO)
  1676.                 return(NO);
  1677.             return(YES);
  1678.         }
  1679.     }
  1680.     else {            /* C = 0 or 255 */
  1681.         if(byteCount == 0) {
  1682.             lastByte = C;
  1683.             byteCount++;
  1684.             if(tryPutc(C, fp) == NO)
  1685.                 return(NO);
  1686.             return(YES);
  1687.         }
  1688.         else        /* byteCount != 0 */
  1689.             if(C != lastByte || byteCount == byte255) {
  1690.                 if(tryPutc(byteCount, fp) == NO)
  1691.                     return(NO);
  1692.                 byteCount = 1;
  1693.                 lastByte = C;
  1694.                 if(tryPutc(C, fp) == NO)
  1695.                     return(NO);
  1696.                 return(YES);
  1697.             }
  1698.             else {
  1699.                 byteCount++;
  1700.             }
  1701.     }
  1702.     return(YES);
  1703. }
  1704.  
  1705. int     tryPutc(ch, fp)
  1706. unsigned char    ch;
  1707. FILE * fp;
  1708. {
  1709.     if(putc(ch, fp) == EOF) {
  1710.                 /* this writes a character and if it encounters
  1711.                    an error, it returns EOF, but EOF may also
  1712.                    be the transmitted character so then we must
  1713.                    check */
  1714.         if(ferror(fp) != 0) {/* 0 means no error */
  1715.             fileFailureWarning();
  1716.             return(NO);
  1717.         }
  1718.     }
  1719.     return(YES);
  1720. }
  1721.  
  1722.  
  1723. fileFailureWarning() {
  1724.     ret_erase_line(2);
  1725.     PRINT
  1726. "\n****************ERROR ENCOUNTERED IN STORING PICTURE*****************\n");
  1727.     PRINT
  1728. "THIS DISK DRIVE MAY BE OUT OF SPACE; TRY STORING THE FILE ON A \n");
  1729.     PRINT
  1730. "DIFFERENT DRIVE BY SPECIFYING A DIFFERENT DRIVE IN FILE NAME; THAT IS, \n");
  1731.     PRINT
  1732. "USE COMMAND \"DN\" WITH A FILE NAME, E.G.,   C:...\n");
  1733.     PRINT 
  1734. "Putting a blank formatted floppy in your drive might NOT work. \n");
  1735.     ret_erase_line(2);
  1736. }
  1737.  
  1738.  
  1739. resetDiameters() {        /* this routine resets the sets
  1740.                    "diameters[ScrnSec]" when the screen is
  1741.                    rescaled using 's' or 'u';
  1742.                    "diameters[ScrnSec]" is needed so that when
  1743.                    the trajectory gets too far away from the
  1744.                    region of interest, the process can be
  1745.                    stopped; this prevents overflow; when
  1746.                    changing the scale so that a small region
  1747.                    can be examined, it is necessary to reset
  1748.                    "diameters" to a correspondingly larger
  1749.                    value */
  1750.     double  maximum,
  1751.             Xratio,
  1752.             Yratio;
  1753.  
  1754.     set_box();
  1755.  
  1756.     Xratio = fabs((X_upp - X_low) / (X_upper - X_lower));
  1757.     Yratio = fabs((Y_upp - Y_low) / (Y_upper - Y_lower));
  1758.     maximum = 1.;
  1759.     if(1 / Xratio > maximum)
  1760.         maximum = 1 / Xratio;
  1761.     if(1 / Yratio > maximum)
  1762.         maximum = 1 / Yratio;
  1763.  
  1764.     if(diameters[ScrnSec] >= 0)
  1765.         diameters[ScrnSec] = maximum * (.5 + diameters[OldScrSec]) -.5;
  1766.  /* diameters: Let d = diameters. Recall that the big window is d windows above
  1767.     and below the screen, so if the screen in one coordinate(Y) runs from -1
  1768.     to 1, then the big window runs from -2*d-1 to 2*d+1, while the new
  1769.     presumably smaller window runs from -Yratio to + Yratio. The big window is
  1770.     (2*d +1)/Yratio times bigger than the little window; if D is the new
  1771.     diameter, then that must be 2D+1 times the little window; hence D =
  1772.     .5*[(2*d + 1)/Yratio -1] = (d + .5)maximum -.5   If d < 0, we do not have
  1773.     to change it because negative values simply means we should ignore it */
  1774. /*PRINT
  1775. "Xratio=%lf,Yratio=%lf,max=%lf,old diam =%lf new diam=%lf\n",
  1776. Xratio,Yratio,maximum,diameters[0],diameters[ScrnSec]);
  1777. */
  1778. }
  1779.  
  1780.  
  1781.  
  1782. reverseCore(x, y)        /* reverses the color( 0 or 1) of core pixel; 
  1783.                 */
  1784. int     x,
  1785.         y;
  1786. {
  1787.     char    pc,
  1788.             maskByte;
  1789.     unsigned        row,
  1790.                     coord;
  1791.  
  1792.  
  1793.  /* first reverse the relevant bit of pic1[] */
  1794.     rowbit = y % 8;
  1795.     row = y / 8;
  1796.     coord = x * corerows + row;
  1797.     maskByte = mask[rowbit];
  1798.  
  1799.     if(colorPlanes >= 4) {
  1800.         if(((pc = pic1[coord]) & maskByte) > 0)
  1801.             pc = pc & ~mask[rowbit];
  1802.                 /* ~m is the complement of m so pc & ~m is the
  1803.                    character that is 0 if either pc or ~m is 0,
  1804.                    that is, the rowbit bit is set to 0 */
  1805.         else        /* if the bit is not now set, then set it */
  1806.             pic1[coord] = pc | mask[rowbit];
  1807.         if(((pc = pic2[coord]) & maskByte) > 0)
  1808.             pc = pc & ~mask[rowbit];
  1809.                 /* ~m is the complement of m so pc & ~m is the
  1810.                    character that is 0 if either pc or ~m is 0,
  1811.                    that is, the rowbit bit is set to 0 */
  1812.         else        /* if the bit is not now set, then set it */
  1813.             pic2[coord] = pc | mask[rowbit];
  1814.         if(((pc = pic4[coord]) & maskByte) > 0)
  1815.             pc = pc & ~mask[rowbit];
  1816.                 /* ~m is the complement of m so pc & ~m is the
  1817.                    character that is 0 if either pc or ~m is 0,
  1818.                    that is, the rowbit bit is set to 0 */
  1819.         else        /* if the bit is not now set, then set it */
  1820.             pic4[coord] = pc | mask[rowbit];
  1821.         if(((pc = pic8[coord]) & maskByte) > 0)
  1822.             pc = pc & ~mask[rowbit];
  1823.                 /* ~m is the complement of m so pc & ~m is the
  1824.                    character that is 0 if either pc or ~m is 0,
  1825.                    that is, the rowbit bit is set to 0 */
  1826.         else        /* if the bit is not now set, then set it */
  1827.             pic8[coord] = pc | mask[rowbit];
  1828.     }
  1829.     else
  1830.         if(colorPlanes >= 1) {
  1831.             if(((pc = pic1[coord]) & maskByte) > 0)
  1832.                 pc = pc & ~mask[rowbit];
  1833.                 /* ~m is the complement of m so pc & ~m is the
  1834.                    character that is 0 if either pc or ~m is 0,
  1835.                    that is, the rowbit bit is set to 0 */
  1836.             else    /* if the bit is not now set, then set it */
  1837.                 pic1[coord] = pc | mask[rowbit];
  1838.         }
  1839. }
  1840.  
  1841.  
  1842.  
  1843. ScreenConstants() {        /* defines ax,bx where x = 0,00,1,2; it is
  1844.                    called by boot_crt() and 's' and 'u' */
  1845.     double  f,
  1846.             fabs();
  1847.     int     ss = ScrnSec;
  1848.  
  1849.  /* In plot() COL = xScrPix*y[0]-b0  (screen col)  */
  1850.     xDifRecip = 1 / fabs(X_upper - X_lower);
  1851.     yDifRecip = 1 / fabs(Y_upper - Y_lower);
  1852.  
  1853.     X_Lo[ss] = X_lower;
  1854.     X_Up[ss] = X_upper;
  1855.     Y_Lo[ss] = Y_lower;
  1856.     Y_Up[ss] = Y_upper;
  1857.  
  1858.     halfscrcols = scrncols / 2;
  1859.     halfscrrows = scrnrows / 2;
  1860.  
  1861.     xScrPix[ScrnSec] = scrncols / (X_upper - X_lower);/* for screen   */
  1862.     xCorPix[ScrnSec] = corecols / (X_upper - X_lower);/* for printer */
  1863.  
  1864.  /* In plot() ROW = -yScrPix*y[1]+b1  (screen row)  */
  1865.     f = Y_upper - Y_lower;
  1866.     yScrPix[ScrnSec] = scrnrows / f;
  1867.     yCorPix[ScrnSec] = 8.* corerows / f;
  1868.  
  1869.     LeftScrEdge[0] = LeftScrEdge[1] = LeftScrEdge[3] = 0;
  1870.     LeftScrEdge[2] = LeftScrEdge[4] = scrncols / 2;
  1871.     RtScrEdge[0] = RtScrEdge[2] = RtScrEdge[4] = scrncols;
  1872.     RtScrEdge[1] = RtScrEdge[3] = scrncols / 2;
  1873.  
  1874.     TopScrEdge[0] = TopScrEdge[1] = TopScrEdge[2] = 0;
  1875.     TopScrEdge[3] = TopScrEdge[4] = scrnrows / 2;
  1876.     BotScrEdge[0] = BotScrEdge[3] = BotScrEdge[4] = scrnrows;
  1877.     BotScrEdge[1] = BotScrEdge[2] = scrnrows / 2;
  1878.  
  1879. }
  1880.  
  1881. int     set_box() {        /* sets the for box edges X_low thru Y_upp to
  1882.                    be x_new_low thru y_new_upp when they have
  1883.                    been set(so they are not the default
  1884.                    values); when they have not been set the
  1885.                    current box edges are used: X_lower thru
  1886.                    Y_upper; notice that no check is made of
  1887.                    whether x_new_low is less than x_new_upp;
  1888.                    these names are misleading since they really
  1889.                    refer to left and right rather than which
  1890.                    coordinate is less than another; returns: 1
  1891.                    if box is inside(or equal to) window 0 if
  1892.                    outside */
  1893.             X_low = x_new_low;
  1894.     if(X_low == -9999)
  1895.         X_low = X_lower;/* equals first argument unless it is -9999, in
  1896.                    which case it equals the second argument */
  1897.     X_upp = x_new_upp;
  1898.     if(X_upp == -9999)
  1899.         X_upp = X_upper;
  1900.  
  1901.     Y_low = y_new_low;
  1902.     if(Y_low == -9999)
  1903.         Y_low = Y_lower;
  1904.  
  1905.     Y_upp = y_new_upp;
  1906.     if(Y_upp == -9999)
  1907.         Y_upp = Y_upper;
  1908.  
  1909.  /* test location of box */
  1910.     if((X_low - X_lower) * (X_upper - X_low) < 0
  1911.             || (Y_low - Y_lower) * (Y_upper - Y_low) < 0
  1912.             || (X_upp - X_lower) * (X_upper - X_upp) < 0
  1913.             || (Y_upp - Y_lower) * (Y_upper - Y_upp) < 0) {
  1914.         scr_rowcol(3, 0);
  1915.         erase_line();
  1916.         PRINT "Box is at least partially outside window\n");
  1917.         return(0);
  1918.     }
  1919.     return(1);
  1920. }
  1921. #endif     /* X11 */
  1922.  
  1923.